package com.element.priorities;

import java.util.PriorityQueue;

import com.element.character.player.Player;

import tools.Variables;
import world.Area;


public class PQueue extends PriorityQueue<Priority>{
	
	public PQueue(int i, PriorityComparator pc) {
		super(i, pc);
	}


	public void addPriority(Priority p){
		this.add(p);
	}
	
	public Priority getPriority(){
		Priority r = this.poll();
		return r;
	}

	
	public static PQueue newPQueue(){
		return new PQueue(Variables.MAX_PRIORITIES, new PriorityComparator());
	}
		
	public PriorityQueue<Priority> removeLastPriority(int queueSize){
		Priority p = this.getPriority();
		if(queueSize != 0){
			this.removeLastPriority(queueSize - 1);
			this.addPriority(p);
		}
		return this;
	}
	
	public void addPriorities(Player player){
		//addPrioritiesByStatus(player);
		addPrioritiesFromArea(player.currentArea);
	}
	
	private void addPrioritiesByStatus(Player player){

	}

	private void addPrioritiesFromArea(Area area){
		PriorityList pl = area.activities;
		for(int i = 0; i < pl.size(); i++){
			if(this.size() == Variables.MAX_PRIORITIES){
				this.removeLastPriority(this.size());
			}
			this.addPriority(pl.get(i));
		}
	}
}